
/**
 * Created by Administrator on 2017/9/21.
 */
$(function () {
	//登录接口对接
	$("#login_btn").on("click",function () {
		var account = $("#login_form input[name='uname']").val();
		var pwd = $("#login_form input[name='upwd']").val();
		
		$.ajax({
			type:"post",
			// url:"http:121.199.1.149:8888/user/myprofile",获取用户信息的接口
			url:"http://121.199.1.149:8888/user/login",
			data:{
				account:account,
				passwd:pwd,
			},
			dataType:"json",
			timeout:180000,
			success:function (res) {
				console.log(res.code);
				console.log(res);
				if(res.code == -6){
				 	alert(res.msg);
				 }else if(res.code == 0){
				 	$.cookie('_lg_ctx_',res.result);
				 	var c = confirm("登录成功是否直接跳转到主页");
				 	if(c){
						window.location.href="index.html"
					}
				 }
			}	
		})
	})
	//点击跳转到注册界面
	$("#skip_register_btn").on('click',function () {
		$("#register").show();
		$("#login").hide();
	})
	
	//获取url中的id
	function getQueryVariable(variable)
	{
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if(pair[0] == variable){return pair[1];}
		}
		return(false);
	}
	// console.log(getQueryVariable("id"));
	var goodsId = getQueryVariable("id");
	if(goodsId){
		$("#login").show();
		$("#register").hide();
	}
	
	
})